<div class="form">

    <?php
    $form = $this->beginWidget('GxActiveForm', array(
        'id' => 'locality-name-form',
        'enableAjaxValidation' => false,
            ));
    ?>

    <p class="note">
        <?php echo Yii::t('app', 'Fields with'); ?> <span class="required">*</span> <?php echo Yii::t('app', 'are required'); ?>.
    </p>

    <?php echo $form->errorSummary($model); ?>

    <div class="row">
        <div class="rowLabel"><?php echo $form->labelEx($model, 'locality_name'); ?>
        </div>
        <div class="rowControl"><?php echo $form->textField($model, 'locality_name', array('maxlength' => 45, 'onkeyup' => "getLocality(this.id)")); ?>
            <?php echo $form->error($model, 'locality_name'); ?>
        </div><!-- row -->
    </div>
<div class="row">
        <div class="rowLabel"><?php echo $form->labelEx($model, 'zone_id'); ?>
        </div>
        <div class="rowControl"><?php echo $form->dropDownList($model, 'zone_id', GxHtml::listDataEx(ZoneName::model()->findAllAttributes(null, true))); ?>
            <?php echo $form->error($model, 'zone_id'); ?>
        </div><!-- row -->
    </div>
    <div class="row">
        <div class="rowLabel"><?php echo $form->labelEx($model, 'status'); ?>
        </div>
        <div class="rowControl"><?php echo $form->dropDownList($model, 'status', array("1" => "Active", "0" => "Inactive")); ?>    
            <?php echo $form->error($model, 'status'); ?>
        </div><!-- row -->
    </div>

    <?php
    /* code user for add jquery ui */
    $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id' => 'mydialog',
        // additional javascript options for the dialog plugin
        'options' => array(
            'title' => 'Change-Password',
            'autoOpen' => false,
        ),
    ));

    $this->endWidget('zii.widgets.jui.CJuiDialog');
    ?>
    
    <div class="row">
        <div class="rowLabel">&nbsp;</div>
        <?php
        echo GxHtml::submitButton(Yii::t('app', 'Save'), array('class' => 'btn btn btn-primary'));
        $this->endWidget();
        ?>
    </div>
</div>
<!-- form -->
<script>
    function getLocality(id){
        var cache = {};
        $( "#"+id ).autocomplete({
            minLength: 2,
            maxLength: 2,
            source: function( request, response ) {
                var term = request.term;
                if ( term in cache ) {
                    response( cache[ term ] );
                    return;
                }
                $.getJSON( "<?php echo Yii::app()->createUrl("localityName/getLocality"); ?>", request, function( data, status, xhr ) {
                    if(data!=0){
                        cache[ term ] = data;                     
                        response( data );}
                   
                });
            }
        });
    }

</script>
<style>
    .ui-autocomplete {
        max-height: 100px;
        overflow-y: auto;
        /* prevent horizontal scrollbar */
        overflow-x: hidden;
    }
    /* IE 6 doesn't support max-height
     * we use height instead, but this forces the menu to always be this tall
    */
    * html .ui-autocomplete {
        height: 100px;
    }
</style>